package com.greenhouse.business.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.greenhouse.business.domain.BizProductAttribute;
import com.greenhouse.business.service.IBizProductAttributeService;
import com.greenhouse.common.annotation.Log;
import com.greenhouse.common.core.controller.BaseController;
import com.greenhouse.common.core.domain.AjaxResult;
import com.greenhouse.common.core.page.TableDataInfo;
import com.greenhouse.common.enums.BusinessType;
import com.greenhouse.common.utils.poi.ExcelUtil;

/**
 * 【请填写功能名称】Controller
 * 
 * @author greenhouse
 * @date 2021-05-06
 */
@RestController
@RequestMapping("/business/attribute")
public class BizProductAttributeController extends BaseController {
	@Autowired
	private IBizProductAttributeService bizProductAttributeService;

	/**
	 * 查询【请填写功能名称】列表
	 */
	@GetMapping("/list")
	public TableDataInfo list(BizProductAttribute bizProductAttribute) {
		startPage();
		List<BizProductAttribute> list = bizProductAttributeService.selectBizProductAttributeList(bizProductAttribute);
		return getDataTable(list);
	}

	@GetMapping("/listByProductId/{productId}")
	public TableDataInfo list(@PathVariable("productId") Long productId) {
		startPage();
		BizProductAttribute bizProductAttribute = new BizProductAttribute();
		bizProductAttribute.setProductId(productId);
		List<BizProductAttribute> list = bizProductAttributeService.selectBizProductAttributeList(bizProductAttribute);
		return getDataTable(list);
	}

	/**
	 * 导出【请填写功能名称】列表
	 */
	@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(BizProductAttribute bizProductAttribute) {
		List<BizProductAttribute> list = bizProductAttributeService.selectBizProductAttributeList(bizProductAttribute);
		ExcelUtil<BizProductAttribute> util = new ExcelUtil<BizProductAttribute>(BizProductAttribute.class);
		return util.exportExcel(list, "attribute");
	}

	/**
	 * 获取【请填写功能名称】详细信息
	 */
	@GetMapping(value = "/{attributeId}")
	public AjaxResult getInfo(@PathVariable("attributeId") Long attributeId) {
		return AjaxResult.success(bizProductAttributeService.selectBizProductAttributeById(attributeId));
	}

	/**
	 * 新增【请填写功能名称】
	 */
	@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BizProductAttribute bizProductAttribute) {
		return toAjax(bizProductAttributeService.insertBizProductAttribute(bizProductAttribute));
	}

	/**
	 * 修改【请填写功能名称】
	 */
	@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BizProductAttribute bizProductAttribute) {
		return toAjax(bizProductAttributeService.updateBizProductAttribute(bizProductAttribute));
	}

	/**
	 * 删除【请填写功能名称】
	 */
	@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attributeIds}")
	public AjaxResult remove(@PathVariable Long[] attributeIds) {
		return toAjax(bizProductAttributeService.deleteBizProductAttributeByIds(attributeIds));
	}
}
